<!--
 * @Author: ChunLai
 * @Date: 2020-12-16 08:55:45
 * @LastEditTime: 2025-11-20 13:53:18
 * @Description: 表格展示已选险种信息
 * @FilePath: \01.latest-short-insure\src\components\RiskTable.vue
-->
<template>
  <div class="risk-table">
    <div class="t_head">
      <span class="t_head_cell tw30">险种</span>
      <span class="t_head_cell tw19">缴费<br />期间</span>
      <span class="t_head_cell tw15">保障<br />期间</span>
      <span class="t_head_cell tw18">基本保<br />险金额</span>
      <span class="t_head_cell tw18">首年<br />保费</span>
    </div>
    <div
      class="t_body"
      v-for="(item, index) in riskInfo"
      :key="`risk_sub${index}`"
    >
      <div class="t_body_tr">
        <span
          class="t_body_td tw30 risk-name"
          :class="item.ismain ? 'main' : 'sub'"
        >
          {{ item.productName }}
        </span>
        <span class="t_body_td tw19">
          {{ item.payendyear | valFormat(item, "payendyear", gysEngName) }}
        </span>
        <span class="t_body_td tw15">
          {{ item.insuYear | valFormat(item, "insuYear", gysEngName) }}
        </span>
        <span class="t_body_td tw18">
          {{ item.amnt | valFormat(item, "amnt", gysEngName) }}
        </span>
        <span class="t_body_td tw18"> {{ item.prem }}元 </span>
      </div>
      <!-- 责任显示 -->
      <div
        class="t_body_tr2 duty_tr"
        v-if="item.dutyPlanList && getZeRenName(item)"
      >
        可选责任：{{ getZeRenName(item) }}
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "RiskTable",
  components: {
  },
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      riskInfo: "risks/showedRisks",
    }),
  },
  filters: {
    valFormat: function (val, itemObj, type, compName) {
      if (type === "insuYear") {
        if (itemObj.insuYearType === "A") {
          if (val === "106") {
            return compName === "guofu" && !itemObj.ismain
              ? "与主险合同一致"
              : "终身";
          } else {
            return "保至" + val + "岁";
          }
        } else if (itemObj.insuYearType === "D") {
          return val.indexOf("天") !== -1 ? val : `${val}天`;
        } else {
          return val + "年";
        }
      }
      if (type === "amnt") {
        // 不显示保额
        if (itemObj.blankAmnt) {
          return "--";
        }
        const uv = itemObj.amntUnit !== void 0 ? itemObj.amntUnit : "元";
        if (val > 10000) {
          return val % 10000 === 0 ? `${val / 10000}万${uv}` : `${val}${uv}`;
        } else if (val) {
          return `${val}${uv}`;
        } else {
          return "--";
        }
      }
      if (type === "payendyear") {
        return val === "趸交" ? "趸交" : val + "年交";
      }
    },
  },
  methods: {
    getZeRenName(item) {
      let res = "";
      let dutys = item.dutyPlanList;
      if (item.jibenTrans && item.planCode) {
        const tranObj = item.jibenTrans;
        let tranStr = "",
          tranArr = [];
        // 可选责任转化的
        for (let key in tranObj) {
          if (tranObj[key] == item.planCode) {
            tranStr = `${key}`;
          }
        }
        tranArr = tranStr.split("");
        dutys.forEach((tagDut) => {
          if (tranArr.includes(tagDut.dutyCode)) {
            if (res.length > 0) {
              res += `+${tagDut.label}`;
            } else {
              res = tagDut.label;
            }
          }
        });
      } else {
        let chks = [];
        chks = dutys.filter((ele) => ele.isChecked);
        if (chks.length > 0) {
          chks.forEach((tagDut) => {
            if (res.length > 0) {
              res += `+${tagDut.label}`;
            } else {
              res = tagDut.label;
            }
          });
        }
      }
      return res;
    },
  },
};
</script>

<style lang="less" scoped>
.tw30 {
  width: 30%;
}
.tw19 {
  width: 19%;
}
.tw15 {
  width: 15%;
}
.tw18 {
  width: 18%;
}

.risk-table {
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #ffe5c5;
  .t_head {
    display: flex;
    background-color: #fffaf3;
    border-bottom: 1px solid #ffe5c5;
    .t_head_cell {
      display: flex;
      align-items: center;
      justify-content: center;
      color: #666666;
      font-size: 12px;
      font-weight: 400;
      padding: 6px 0;
      line-height: 1.3;
      letter-spacing: 1px;
    }
  }
  .t_body {
    &:not(:last-child) {
      border-bottom: 1px solid #ffe5c5;
    }
    &:nth-child(odd) {
      background-color: #fffaf3;
    }
    .t_body_tr {
      display: flex;
    }
  }
}
.duty_tr {
  font-size: 12px;
  color: #747474;
  padding: 0 10px;
  margin-bottom: 4px;
}
.amnt_prem_val {
  display: flex;
  align-items: center;
  margin-top: 2px;
}
.t_body_td {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666666;
  font-size: 12px;
  font-weight: 400;
  padding: 10px 8px;
  line-height: 1.3;
  word-break: break-all;
  &.risk-name {
    justify-content: flex-start;
    position: relative;
    padding-top: 13px;
    &.main {
      &::after {
        content: "主";
        position: absolute;
        top: 0;
        left: 0;
        width: 17px;
        height: 12px;
        line-height: 12px;
        text-align: center;
        font-size: 10px;
        color: #ffffff;
        border-radius: 0px 0px 2px 0px;
        background: #f54040;
      }
    }

    &.sub {
      &::after {
        content: "附";
        position: absolute;
        top: 0;
        left: 0;
        width: 17px;
        height: 12px;
        line-height: 12px;
        text-align: center;
        font-size: 10px;
        color: #ffffff;
        border-radius: 0px 0px 2px 0px;
        background: #ff8d1a;
      }
    }
  }
}

table {
  table-layout: fixed;
  empty-cells: show;
  border-collapse: collapse;
  margin: 0 auto;
}
.duty_table {
  width: 100%;
  border-collapse: collapse;

  thead {
    background-color: #ffffff;

    tr {
      th {
        color: #666666;
        font-weight: normal;
        padding: 6px 0;
        line-height: 1;
        text-align: center;
        border: 1px solid #e6e6e6;

        &.w40 {
          width: 40%;
        }
      }
    }
  }

  td {
    color: #666666;
    padding: 6px 0;
    text-align: center;
    border: 1px solid #e6e6e6;
  }
}

.total-fee {
  font-size: 18px;
  font-family: D-DIN-Bold;
  color: #d44438;
}

.top_line {
  border-top: 1px solid #ffe5c5;
}
</style>
